package ui;

import javax.swing.*;
import java.awt.*;
import java.awt.event.*;

/** GUI for the interest calculator
 * @author Matthias
 * @author Niels Christian
 *
 */
public class AccInterestRate extends JPanel{
	
	private JLabel lb_Header;
	private JTextField textField_EndYear;
	private JButton btn_Calculate;
	private JButton btn_Back;
	private JLabel lbl_Intro;
	private JTextArea textArea_Print;
	private JLabel logo_ATM;
		
	/**
	 * Contains the information/blueprint on labels, buttons, text areas and text fields
	 * Sets the window Dimensions
	 */
	public AccInterestRate() {

		setPreferredSize(new Dimension(600, 480));
		setLayout(null);
		
		lb_Header = new JLabel("Account Interest Rate Calculater");
		lb_Header.setFont(new Font("SansSerif", Font.BOLD, 26));
		lb_Header.setBounds(120, 15, 401, 34);
		add(lb_Header);
		
		textField_EndYear = new JTextField();
		textField_EndYear.setFont(new Font("SansSerif", Font.PLAIN, 16));
		textField_EndYear.setBounds(152, 125, 150, 35);
		add(textField_EndYear);
		textField_EndYear.setColumns(10);
		
		btn_Calculate = new JButton("Calculate");
		btn_Calculate.setFont(new Font("SansSerif", Font.PLAIN, 16));
		btn_Calculate.setBounds(152, 175, 130, 50);
		add(btn_Calculate);

		btn_Back = new JButton("Back");
		btn_Back.setFont(new Font("SansSerif", Font.PLAIN, 16));
		btn_Back.setBounds(85, 325, 130, 50);
		add(btn_Back);
		
		lbl_Intro = new JLabel("Please enter a future year until the next 10 years");
		lbl_Intro.setFont(new Font("SansSerif", Font.BOLD, 16));
		lbl_Intro.setBounds(152, 93, 388, 21);
		add(lbl_Intro);
		
		textArea_Print = new JTextArea();
		textArea_Print.setBounds(347, 125, 193, 250);
		textArea_Print.setFont(new Font("SansSerif", Font.ITALIC, 16));
		textArea_Print.setEditable(false);
		textArea_Print.setLineWrap(true);
		textArea_Print.setWrapStyleWord(true);
		add(textArea_Print);
		
		logo_ATM = new JLabel("");
		logo_ATM.setIcon(new ImageIcon(AccInterestRate.class.getResource("/pic/LOGO Mini.png")));
		logo_ATM.setBounds(15, 15, 50, 50);
		add(logo_ATM);
	}
	
	/**
	 * Clears text fields
	 */
	public void clearField() {
		textField_EndYear.setText("");
	}
	
	/** Clears the text area on startup and prints values 
	 * @param values
	 */
	public void showTextArea(String values){ 
		textArea_Print.setText(" ");
		textArea_Print.append(values);
	}

	/** Actionlistener for back and calculate buttons
	 * @param e
	 */
	public void addActionListener(ActionListener e){
		btn_Back.addActionListener(e);
		btn_Calculate.addActionListener(e);
	}
	
	/**
	 * @return the back button
	 */
	public JButton getBtnBack() {
		return btn_Back;
	}

	/**
	 * @return the calculate button
	 */
	public JButton getBtnCalculate() {
		return btn_Calculate;
	}
	
	/**
	 * @return the end year
	 */
	public int getEndYear() {
		int endYear = 0;
		try {
			endYear = Integer.parseInt(textField_EndYear.getText().trim());
		} catch (Exception exc) {
			exc.getMessage();
		}
		return endYear;
	}
} // end class AccInterestRate